<template>
    <div class="exam-container">
      <el-skeleton :loading="isFirst" :rows="15" animated>
      <el-descriptions title="试题详情" direction="vertical" :column="3" border>
        <!-- column为每行2列 如果列中将span设置为2 则何为1列 -->
  
        <el-descriptions-item label="题干" :span="3">
          {{content}}
        </el-descriptions-item>


        <el-descriptions-item label="类型">
            <el-tag>{{qtype==1?"选择题":"简答题"}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="难度" :span="1" width="25%">
            <el-tag>{{lv}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="发布" :span="1" width="25%">
          <el-tag type="success">{{isPublish==0?"否":"是"}}</el-tag>
        </el-descriptions-item>


        <el-descriptions-item label="禁用">
            <el-tag type="danger">{{isBan==0?"否":"是"}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="使用次数" :span="1" width="25%">
          <el-tag>{{topicCount}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="标签" :span="1" width="25%">
          <el-tag>{{labels}}</el-tag>
        </el-descriptions-item>
  
        <el-descriptions-item label="时间" width="50%" :span="1">
          <el-tag>{{createTime}}</el-tag>
        </el-descriptions-item>
  
        <el-descriptions-item label="描述" :span="2">
          <el-tag>{{remark=="" || remark==null ?"-":remark}}</el-tag>
        </el-descriptions-item>

        
        <el-descriptions-item label="参考答案" :span="3">
          <div v-if="optionData.length!=0">
            <div v-for="(item,index) in optionData"  :key="index">
            
            <div class="options" v-if="item.isRight==0" > 
              <div class="xuan-danger" > <el-button type="danger" size="small" :icon="CloseBold" class="icons-danger" circle /> {{ item.content}}</div>
              <div  class="xuan-yellow"> <el-button type="warning" size="small" class="icons-yellow" :icon="Warning" circle /> 选取率：0%</div>
            </div>
          
           
  
            <div class="options" v-if="item.isRight==1"> 
            <div type="success"  class="xuan-success"> <el-button type="success" size="small" :icon="Select" class="icons-success" circle /> {{ item.content}} </div>
            <div  class="xuan-yellow"> <el-button type="warning" size="small" class="icons-yellow" :icon="Warning" circle /> 选取率：0%</div>
          </div>
        </div>
          </div>
 

      <div v-if="optionData.length==0 && answer!=''">
            <div class="options"> 
            <div type="success"  class="xuan-success answer">  {{ answer}} </div>
          </div>
        </div>
        </el-descriptions-item>

        


      </el-descriptions>
    </el-skeleton>
    </div>
  </template>
  
  <script lang="ts">
  import { defineComponent, reactive, toRefs, watchEffect } from 'vue'
  import { getQuestionDetails ,getQuestionOptions} from '../../../api/exam'
  import { ElMessageBox ,ElMessage} from 'element-plus'
  import {  Check,CloseBold ,Warning,Select} from '@element-plus/icons-vue'
  import { useRoute, useRouter } from 'vue-router'
  import type { topicDetailsDto } from '@/dto/question/TopicDetailsDto'
  export default defineComponent({
    setup() {
      const router = useRouter();
      const routes= useRoute();
      const data = reactive<topicDetailsDto>({
        isFirst:true,
        content:"",
        qtype:1,
        isPublish:0,
        lv:0,
        isBan:0,
        topicCount:0,
        labels:"",
        createTime:'',
        remark:"",
        optionData:[],
        answer:""   
      })
  
      /**
       * 事件
       */
      const events = {
        /**
         * 获取默认题库题目的详情
         */
        getQuestionDetails: (tid:any) => {
          getQuestionDetails({id:tid}).then((res:any)=>{
            data.isFirst=false;
              if(res.result===0){
                let result=res.data;
                data.content= result.content;
                data.qtype= result.type;
                data.lv=result.lv;
                data.isPublish=result.isPublish;
                data.isBan=result.isBan;
                data.topicCount=result.useCount;
                data.labels=result.labels;
                data.createTime=result.createTime ;
                data.remark=result.explain;
                data.optionData=result.options;
                data.answer=result.answer;
                
              }else{
                ElMessage.error("维护中");
              }
               
              })
        },
        
        /**
         * 根据题目Id查询题目选项
         * @param tid  题目id
         */
        // getQuestionOptions:(tid:any)=>{
        //   getQuestionOptions({id:tid}).then((res:any)=>{
        //        data.optionData=res.data[0];
        //        console.log(data.optionData);
        //   })
        // }  
      }
      /**
       * 事件
       */

        watchEffect(()=>{
         events.getQuestionDetails(routes.params.tid);
        //  events.getQuestionOptions(routes.params.tid)
        
         
  
     })
       
  
      return {
        ...toRefs(data),
        ...events,
        Check,CloseBold,Warning,Select
      }
    }
  })
  </script>

  <style scoped>
     .xuan-danger,.xuan-danger:hover{
      border: 0;
      color:#f56c6c;
      background: #fef0f0;
      width: 82%;
      height: 40px;
      line-height: 36px;
      border-radius: 4px;
    }

    .options{
      display: flex;
      justify-content: space-between;
    }

    .xuan-danger,.xuan-yellow,.xuan-success{
      margin-left: 0px;
      margin-top: 10px;
    }

    .icons-danger,.icons-danger:hover,.icons-danger:active{
      cursor: default;
      background: #f56c6c;;
      border:0;
      margin-left: 14px;
    }

    
    .xuan-yellow,.xuan-yellow:hover{
      border: 0;
      background: #fdf6ec;
      width: 17%;
      height: 40px;
      border-radius: 4px;
      line-height: 36px;
      color: #e6a23c;
    }

    .icons-yellow,.icons-yellow:hover,.icons-yellow:active{
      cursor: default;
      background: #e6a23c;;
      border:0;
      margin-left:14px;
      font-size: 29px;
    }


    .xuan-success,.xuan-success:hover{
      border: 0;
      color:#67c23a;
      background: #f0f9eb;
      width: 82%;
      height: 40px;
      line-height: 36px;
      border-radius: 4px;
    }

    .answer,.answer:hover{
      width: 98%;
      padding-left: 10px;
    }

    .icons-success,.icons-success:hover,.icons-success:active{
      cursor: default;
      background: #67c23a;
      border:0;
      margin-left:14px;
    }

  </style>
  